1. Introducción

Column

Datos de la muestra

Muestra

Economías más grandes del mundo

50

Hipótesis

  • Pregunta de investigación: ¿Qué factores sociales y económicos han influido en el crecimiento y/o variaciones del PIB entre los años 2020 y 2021 en las 50 economías más grandes del mundo?

  • Justificación: El estudio del crecimiento económico mediante el PIB, y de sus determinantes, es fundamental para entender los diversos procesos sociales que pueden estar interrelacionados con dicho crecimiento. El análisis de estos 50 países, los cuales representan a la mayor parte de la economía global, nos ofrece una amplia y valiosa visión comparativa. El período comprendido entre el 2020 y el 2021 es de particular interés dados los efectos que trajo consigo la pandemia de COVID-19. Esto nos permitirá entonces observar de manera directa dichos efectos durante el tiempo de la crisis. El comprender las variables que impulsan el crecimiento económico puede permitirnos conocer acerca de la toma de decisiones de políticas públicas en dicho período. Finalmente, creemos que la originalidad del presente trabajo recae en el enfoque de tomar en cuenta a las 50 economías más grandes del mundo, junto con las demás variables que expondremos más adelante.

  • Hipótesis: Esperamos que, dado que el PIB es nuestra variable independiente, tenga cierta variación del año 2020 al 2021, bajo la influencia de nuestras variables independientes, que abarcan cuestiones sociopolíticas y económicas. Con ello, y teniendo en cuenta el contexto de la pandemia de COVID-19, esperamos que el PIB de dichas economías crezca.

Column {data-width=400}

Distribución del crecimiento del PBI en 2021

2. Análisis factorial

Column {data-width=500}

Correlación de las variables

Column {data-width=500}

Prueba KMO

Kaiser-Meyer-Olkin factor adequacy
Call: psych::KMO(r = corMatrix)
Overall MSA =  0.61
MSA for each item = 
          exports_gdp_por            GDP_growth_por GDP_per_capita_growth_por 
                     0.40                      0.47                      0.48 
           edu_govexp_gdp            inflation_rate              military_gdp 
                     0.54                      0.67                      0.36 
           health_exp_gdp             R_._D_exp_GDP                   gov_eff 
                     0.69                      0.76                      0.70 
             UHC_coverage 
                     0.77 

Prueba de Matriz de Identidad

[1] FALSE

Prueba de Matriz Singular

[1] FALSE

Factores Recomendados

Parallel analysis suggests that the number of factors =  2  and the number of components =  NA 

Loadings:
                          ML2    ML1   
exports_gdp_por            0.367  0.301
GDP_growth_por            -0.150  0.926
GDP_per_capita_growth_por         0.997
edu_govexp_gdp             0.369       
inflation_rate             0.381       
military_gdp                           
health_exp_gdp             0.698       
R_._D_exp_GDP              0.787       
gov_eff                    0.898       
UHC_coverage               0.786  0.207

                 ML2   ML1
SS loadings    2.972 2.017
Proportion Var 0.297 0.202
Cumulative Var 0.297 0.499

Loadings:
                          ML2    ML1   
exports_gdp_por                        
GDP_growth_por                    0.926
GDP_per_capita_growth_por         0.997
edu_govexp_gdp                         
inflation_rate                         
military_gdp                           
health_exp_gdp             0.698       
R_._D_exp_GDP              0.787       
gov_eff                    0.898       
UHC_coverage               0.786       

                 ML2   ML1
SS loadings    2.972 2.017
Proportion Var 0.297 0.202
Cumulative Var 0.297 0.499

Resultados del Análisis Factorial

3. Regresiones

Column {data-width=500}

Regresión Gaussiana: Variables Independientes


Call:
lm(formula = modelo27, data = locura)

Residuals:
    Min      1Q  Median      3Q     Max 
-1.7845 -0.6202 -0.2311  0.7530  2.1536 

Coefficients:
                 Estimate Std. Error t value Pr(>|t|)  
(Intercept)     -2.267443   1.313042  -1.727   0.0917 .
exports_gdp_por  0.010898   0.006261   1.741   0.0893 .
edu_govexp_gdp   0.008736   0.075180   0.116   0.9081  
inflation_rate  -0.004943   0.014809  -0.334   0.7402  
military_gdp     0.074521   0.136863   0.544   0.5890  
health_exp_gdp   0.028566   0.075809   0.377   0.7083  
R_._D_exp_GDP   -0.093873   0.176904  -0.531   0.5985  
gov_eff         -0.254658   0.353796  -0.720   0.4757  
UHC_coverage     0.021370   0.021482   0.995   0.3257  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.998 on 41 degrees of freedom
Multiple R-squared:  0.1625,    Adjusted R-squared:  -0.000881 
F-statistic: 0.9946 on 8 and 41 DF,  p-value: 0.4546

6. Análisis conglomerado

Column {data-width=500}

Datos

Clusters PAM

Clusters AGNES:

Clusters DIANA

Column {data-width=500}

Datos PAM

  pam exports_gdp_por GDP_growth_por GDP_per_capita_growth_por edu_govexp_gdp
1   1        42.78069       6.894483                  6.485517       4.122414
2   2        43.67381       5.344762                  5.065238       5.578571
  inflation_rate military_gdp health_exp_gdp R_._D_exp_GDP   gov_eff
1      -11.47966     1.955172       5.955172     0.7758621 0.1344828
2       -3.52619     1.704762      11.142857     2.8333333 1.4333333
  UHC_coverage
1     72.65517
2     86.00000

Silueta PAM

Datos AGNES

  agnes exports_gdp_por GDP_growth_por GDP_per_capita_growth_por edu_govexp_gdp
1     1        34.24333       6.444074                  5.872963       4.211852
2     2        53.61826       6.008261                  5.907826       5.346957
  inflation_rate military_gdp health_exp_gdp R_._D_exp_GDP     gov_eff
1     -11.909259     1.996296       5.959259     0.7185185 0.007407407
2      -3.713478     1.678261      10.686957     2.7217391 1.469565217
  UHC_coverage      pam
1     71.66667 1.000000
2     86.00000 1.913043

Silueta AGNES

Datos DIANA

  diana exports_gdp_por GDP_growth_por GDP_per_capita_growth_por edu_govexp_gdp
1     1        38.36917       5.963125                  5.519583       4.809792
2     2       158.03500      12.975000                 14.755000       2.915000
  inflation_rate military_gdp health_exp_gdp R_._D_exp_GDP gov_eff UHC_coverage
1      -8.241667      1.86875       8.227083       1.64375 0.63125      77.9375
2      -5.680000      1.40000       5.900000       1.55000 1.85000      86.0000
     pam  agnes
1 1.4375 1.4375
2 1.0000 2.0000

Silueta DIANA:

7. Conclusiones

Column {data-width=500}

Hipótesis 1:


Call:
lm(formula = modelo11, data = locura)

Residuals:
    Min      1Q  Median      3Q     Max 
-1.7683 -0.6470 -0.2185  0.6615  2.0463 

Coefficients:
                 Estimate Std. Error t value Pr(>|t|)  
(Intercept)     -0.392456   0.224604  -1.747   0.0870 .
exports_gdp_por  0.009094   0.004144   2.194   0.0331 *
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.9608 on 48 degrees of freedom
Multiple R-squared:  0.09118,   Adjusted R-squared:  0.07225 
F-statistic: 4.816 on 1 and 48 DF,  p-value: 0.03307

Interpretación Hipótesis 1:

Hipótesis 2:


Call:
lm(formula = modelo30, data = locura)

Residuals:
    Min      1Q  Median      3Q     Max 
-1.3148 -0.7701 -0.2063  0.4487  2.9161 

Coefficients:
                Estimate Std. Error t value Pr(>|t|)
(Intercept)    -0.147720   0.418778  -0.353    0.726
edu_govexp_gdp  0.034164   0.060702   0.563    0.576
health_exp_gdp -0.001723   0.046854  -0.037    0.971

Residual standard error: 1.015 on 47 degrees of freedom
Multiple R-squared:  0.007232,  Adjusted R-squared:  -0.03501 
F-statistic: 0.1712 on 2 and 47 DF,  p-value: 0.8432

Interpretación Hipótesis 2:

Hipótesis 3:


Call:
lm(formula = modelo31, data = locura)

Residuals:
     Min       1Q   Median       3Q      Max 
-1.65719 -0.63075 -0.08479  0.42625  2.63613 

Coefficients:
               Estimate Std. Error t value Pr(>|t|)  
(Intercept)    -1.84992    1.05547  -1.753   0.0863 .
edu_govexp_gdp  0.01214    0.06073   0.200   0.8425  
health_exp_gdp -0.06715    0.05917  -1.135   0.2623  
UHC_coverage    0.02988    0.01708   1.750   0.0868 .
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.9933 on 46 degrees of freedom
Multiple R-squared:  0.06921,   Adjusted R-squared:  0.008503 
F-statistic:  1.14 on 3 and 46 DF,  p-value: 0.3429

Interpretación Hipótesis 3:

Hipótesis 4:


Call:
lm(formula = modelo32, data = locura)

Residuals:
    Min      1Q  Median      3Q     Max 
-1.6862 -0.6210 -0.1005  0.6069  2.5586 

Coefficients:
               Estimate Std. Error t value Pr(>|t|)  
(Intercept)    -2.25063    1.13072  -1.990   0.0526 .
edu_govexp_gdp  0.01016    0.06078   0.167   0.8680  
health_exp_gdp -0.04684    0.06264  -0.748   0.4584  
UHC_coverage    0.03598    0.01816   1.982   0.0537 .
R_._D_exp_GDP  -0.14153    0.14304  -0.989   0.3277  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.9935 on 45 degrees of freedom
Multiple R-squared:  0.08903,   Adjusted R-squared:  0.008051 
F-statistic: 1.099 on 4 and 45 DF,  p-value: 0.3685

Interpretación Hipótesis 4:

---
title: "Determinantes del Crecimiento Económico"
author: "Augusto Granados y Leonardo Argandoña"
output: 
  flexdashboard::flex_dashboard:
    theme: journal
    orientation: columns
    vertical_layout: fill
    source_code: embed
---

<style>
.scroll-box {
height: calc(100vh - 120px); /* 100% de la altura de la ventana menos 120px */
overflow-y: auto; /* Añade scroll vertical si es necesario */
padding-right: 15px; /* Espacio opcional para la barra de scroll */
}
</style>

1. Introducción {data-icon="fa-solid fa-lightbulb"}
=====================================

Column {data-width=650}
-----------------------------------------------------------------------

```{r setup, include=FALSE}
library(flexdashboard)
library(stringi)
library(ggplot2)
library(corrplot)
library(dplyr)
library(rio)
library(tidyverse)
library(BBmisc)
library(ggthemes)
library(polycor)
library(psych)
library(matrixcalc)
library(GPArotation)
library(cluster)
library(factoextra)
library(kableExtra)
library(modelsummary)
library(plotly)
library(sf)
library(ggrepel)
library(leaflet)
library(DT)
library(fontawesome)
library(vtable)
library(reshape2)
library(tmap)

htmltools::tagList(fontawesome::fa_html_dependency())

computeMuestra = function(...) return("Muestra")
computePaises = function(...) return(50)

setwd("C:/Users/Augusto/Desktop/Ciclo 2025-1/Estadistica para el Análisis Político 2/EAP2 - Tf")


link_locura="https://docs.google.com/spreadsheets/d/e/2PACX-1vRlKbBagehW10J-kbK9KsXDd6wbJ21TWUTkv-NFRw7F1Ne0earsXK0Iv6v4Qnxb0xwfYHDh4IRoRySE/pub?gid=1509063522&single=true&output=csv"
locura=read.csv(link_locura)
names(locura)

locura$inflation_rate=-1*locura$inflation_rate

boxplot(BBmisc::normalize(locura[,2:11],method='standardize'))


```

### Datos de la muestra
```{r}
muestra = computeMuestra()
valueBox(muestra, icon = "fa-solid fa-flask")
```

### Economías más grandes del mundo 

```{r}
paises = computePaises()
valueBox(paises, icon = "fas fa-earth-americas")
```

### Hipótesis

* **Pregunta de investigación:**
¿Qué factores sociales y económicos han influido en el crecimiento y/o variaciones del PIB entre los años 2020 y 2021 en las 50 economías más grandes del mundo?

* **Justificación:**
El estudio del crecimiento económico mediante el PIB, y de sus determinantes, es fundamental para entender los diversos procesos sociales que pueden estar interrelacionados con dicho crecimiento. El análisis de estos 50 países, los cuales representan a la mayor parte de la economía global, nos ofrece una amplia y valiosa visión comparativa. El período comprendido entre el 2020 y el 2021 es de particular interés dados los efectos que trajo consigo la pandemia de COVID-19. Esto nos permitirá entonces observar de manera directa dichos efectos durante el tiempo de la crisis. El comprender las variables que impulsan el crecimiento económico puede permitirnos conocer acerca de la toma de decisiones de políticas públicas en dicho período. Finalmente, creemos que la originalidad del presente trabajo recae en el enfoque de tomar en cuenta a las 50 economías más grandes del mundo, junto con las demás variables que expondremos más adelante.

* **Hipótesis:**
Esperamos que, dado que el PIB es nuestra variable independiente, tenga cierta variación del año 2020 al 2021, bajo la influencia de nuestras variables independientes, que abarcan cuestiones sociopolíticas y económicas. Con ello, y teniendo en cuenta el contexto de la pandemia de COVID-19, esperamos que el PIB de dichas economías crezca. 


Column {data-width=400}{.tabset}
-----------------------------------------------------------------------

### Distribución del crecimiento del PBI en 2021


```{r}
locura %>%
  ggplot(aes(x = GDP_growth_por)) + 
  geom_histogram(color = "black", fill = "hotpink1", bins = 40) +
  ggtitle("Crecimiento anual del PBI de las 50 economías más grandes del mundo en 2021") +
  ylab("Frecuencia")+xlab("Tasa anual del crecimiento del PBI")+
  geom_vline(xintercept =  mean(locura$GDP_growth_por, na.rm = TRUE), color = "red", linetype = "dashed", size = 1) + # Línea de la media
  geom_vline(xintercept = median(locura$GDP_growth_por, na.rm = TRUE), color = "grey", linetype = "dashed", size = 1) + # Línea de la mediana
  theme_minimal()
```


2. Análisis factorial {data-icon="fa-solid fa-layer-group"}
===================================== 

Column {data-width=500}{.tabset}
-----------------------------------------------------------------------

```{r}
dontselect=c("COUNTRY")
select=setdiff(names(locura),dontselect)
theData=locura[,select]
row.names(theData)=locura$COUNTRY
```


### Correlación de las variables

```{r}
corMatrix=polycor::hetcor(theData)$correlations

ggcorrplot::ggcorrplot(corMatrix)
```

Column {data-width=500}{.tabset}
-----------------------------------------------------------------------

### Prueba KMO

```{r}
psych::KMO(corMatrix) 
```

### Prueba de Matriz de Identidad

```{r}
cortest.bartlett(corMatrix,n=nrow(theData))$p.value>0.05
```

### Prueba de Matriz Singular

```{r}
is.singular.matrix(corMatrix)
```

### Factores Recomendados

```{r}
psych::fa.parallel(theData, fa = 'fa',correct = T,plot = F,fm = 'ml')
```


::::: {.scroll-box}
```{r}
resfa <- psych::fa(theData,
            nfactors =2,
            cor = 'mixed',
            rotate = "varimax", #oblimin?
            fm="ml")
print(resfa$loadings)
```
:::::


```{r}
print(resfa$loadings,cutoff = 0.5)
```


### Resultados del Análisis Factorial

```{r}
psych::fa.diagram(resfa,main = "Resultados del EFA")
```

```{r}
locura$ice_efa=resfa$scores[,2]
```


3. Regresiones {data-icon="fa-solid fa-wave-square"}
===================================== 

Column {data-width=500}{.tabset}
-----------------------------------------------------------------------

### Regresión Gaussiana: Variables Independientes

```{r}
modelo27=formula(ice_efa~exports_gdp_por+edu_govexp_gdp+inflation_rate+military_gdp+health_exp_gdp+R_._D_exp_GDP+gov_eff+UHC_coverage)

reg27=lm(modelo27,data=locura)
summary(reg27)
```

6. Análisis conglomerado {data-icon="fa-solid fa-object-ungroup"}
===================================== 

Column {data-width=500} {.tabset}
-----------------------------------------------------------------------

### Datos

```{r}
boxplot(BBmisc::normalize(locura[,2:11],method='standardize'))
```

```{r}
dataClus=locura[,c(2:11)]
row.names(dataClus)=locura$COUNTRY
```

```{r}
library(cluster)
g.dist = daisy(dataClus, metric="gower")
```


### Clusters PAM

```{r}
library(factoextra)
fviz_nbclust(dataClus, pam,diss=g.dist,method = "gap_stat",k.max = 10,verbose = F)
```

### Clusters AGNES:
```{r}
fviz_nbclust(dataClus,hcut,diss=g.dist,method = "gap_stat",k.max = 10,verbose = F,hc_func = "agnes")
```

### Clusters DIANA

```{r}
fviz_nbclust(dataClus, hcut,diss=g.dist,method = "gap_stat",k.max = 10,verbose = F,hc_func = "diana")
```

Column {data-width=500} {.tabset}
-----------------------------------------------------------------------
### Datos PAM

```{r}
library(kableExtra)
set.seed(123)
res.pam=pam(g.dist,2,cluster.only = F)

#nueva columna
dataClus$pam=res.pam$cluster

aggregate(.~ pam, data=dataClus,mean)
```

### Silueta PAM

```{r}
fviz_silhouette(res.pam,print.summary = F)
```

### Datos AGNES

```{r}
set.seed(123)
library(factoextra)

res.agnes<- hcut(g.dist, k = 2,hc_func='agnes',hc_method = "ward.D")

dataClus$agnes=res.agnes$cluster

aggregate(.~ agnes, data=dataClus,mean)
```


### Silueta AGNES

```{r}
fviz_silhouette(res.agnes,print.summary = F)
```

### Datos DIANA

```{r}
set.seed(123)
res.diana <- hcut(g.dist, k = 2,hc_func='diana')
dataClus$diana=res.diana$cluster

aggregate(.~ diana, data=dataClus,mean)
```

### Silueta DIANA:

```{r}
fviz_silhouette(res.diana,print.summary = F)
```


7. Conclusiones {data-icon="fa-solid fa-layer-group"}
===================================== 

Column {data-width=500}{.tabset}
-----------------------------------------------------------------------

### Hipótesis 1:

```{r}
modelo11=formula(ice_efa~exports_gdp_por)
reg11=lm(modelo11,data=locura)
summary(reg11)
```
### Interpretación Hipótesis 1:

### Hipótesis 2:
```{r}
modelo30=formula(ice_efa~edu_govexp_gdp+health_exp_gdp)
reg30=lm(modelo30,data=locura)
summary(reg30)
```
### Interpretación Hipótesis 2:

### Hipótesis 3:

```{r}
modelo31=formula(ice_efa~edu_govexp_gdp+health_exp_gdp+UHC_coverage)
reg31=lm(modelo31,data=locura)
summary(reg31)
```

### Interpretación Hipótesis 3:

### Hipótesis 4:
```{r}
modelo32=formula(ice_efa~edu_govexp_gdp+health_exp_gdp+UHC_coverage+R_._D_exp_GDP)
reg32=lm(modelo32,data=locura)
summary(reg32)
```

### Interpretación Hipótesis 4: